var common_service = angular.module('OtherService');
common_service.service('common_service',['$ionicPopup',function($ionicPopup){
  var self = this;
  self.pop1 = function(scope){
    var myPopup = $ionicPopup.show({
             template: '<div class="cf" style="margin-top:1em;border-bottom: 2px solid #E7E7EA;"><label style="position:absolute;line-height:2.4;color:#aaa;font-size:12px;">姓名：</label><input maxlength="12" style="font-size:12px;text-align:right;" placeholder="请填写真实姓名" type="text" ng-model="data.name"></div>'
             +'<div class="cf" style="border-bottom: 2px solid #E7E7EA;"><label style="position:absolute;line-height:2.4;color:#aaa;font-size:12px;">身份证号：</label><input maxlength="18" style="font-size:12px;text-align:right;" placeholder="请填写身份证号码" type="text" ng-model="data.cardId"></div>'
             +'<div class="cf" style="border-bottom: 2px solid #E7E7EA;"><label style="position:absolute;line-height:2.4;color:#aaa;font-size:12px;">手机号码：</label><input maxlength="11" style="font-size:12px;text-align:right;" placeholder="请填写您常用的手机号码" type="text" ng-model="data.phone"></div>'
             +'<p style="line-height:2;color:#999;">注：所有信息博朗斯为您保密</p>',
             title: '为保障您的协议权利<br>请如实填写您的身份信息',
             scope: scope,
             buttons: [
               {
                 text: '<span style="font-size:12px;">确&nbsp;&nbsp;定</span>',
                 type: 'button-energized',
                 onTap: function(e) {
                   if ( scope.data.name && scope.data.cardId && scope.data.phone) {
                     return scope.data;
                   } else {
                     e.preventDefault();
                   }
                 }
               },
             ]
           });
    return myPopup;
  }
}]);
common_service.service('wenku_service',[function(){
  var self = this;
  self.Model = {};
}]);
common_service.service('yamiinfo_service',[function(){
  var self = this;
  self.Model = {};
}]);
common_service.service('zuotijilv_service',['api_other',function(api_other){
  var self = this;
  self.Model = {};
  self.get = function(){
    var obj = {
      catId:localStorage.catId,
      userId:localStorage.bls_userId
    };
    var promise = api_other.treeNum(obj);
    promise.success(function(data){
      if(data.returnCode == 0){
        self.Model = data.returnData;
      }
    });
    return promise;
  };
  self.set = function(id,type){
    var obj = {
      collectId:id,
      userId:localStorage.bls_userId,
      type:type,
    };
    var promise = api_other.zuotijilv(obj);
    promise.success(function(data){
    });    
  }
}]);
common_service.service('weixinbuy_service',['api_other',function(api_other){
  var self = this;
  self.submit = function(orderId,type){
    var obj = {
      orderId:orderId,
      userId:localStorage.bls_userId,
      type:type
    };
    var promise = api_other.goumai(obj);
    promise.success(function(data){
      if(data.returnCode == 0){
        var obj = data.returnData;
           WeixinJSBridge.invoke(
               'getBrandWCPayRequest', {
                   appId : obj.appId,     //公众号名称，由商户传入     
                   timeStamp:obj.timeStamp+"",         //时间戳，自1970年以来的秒数     
                   nonceStr : obj.nonceStr+"", //随机串     
                   package : obj.package,     
                   signType : obj.signType,         //微信签名方式:     
                   paySign : obj.paySign //微信签名 

               },
               function(res){     
                   if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                    alert('支付成功');
                    $state.go('main.bls');
                   }else{
                    alert('支付失败'+res.err_msg);
                   }
               }
           ); 
        /*if (typeof WeixinJSBridge == "undefined"){
           if( document.addEventListener ){
               document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
           }else if (document.attachEvent){
               document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
               document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
           }
        }else{
           onBridgeReady();
        }*/           
      }
    });
  };
}]); 